﻿Imports Framework.Data

Public Class Settings
    Private Shared mSettingsRead As Boolean = False
    Private Shared mWorkingFolder As String
    Private Shared mGlobalFileFilter As Entities.Backup.FileFilter

    Friend Shared ReadOnly SettingsKey As String = "Backup"

    Public Shared ReadOnly Property WorkingFolder() As String
        Get
            If Not mSettingsRead Then LoadSettings()
            Return mWorkingFolder
        End Get
    End Property
    Public Shared Sub SetWorkingFolder(ByVal value As String, ByVal transactionScope As TransactionScope)
        If Not mSettingsRead Then LoadSettings()
        If mWorkingFolder <> value Then
            Framework.Data.MetaData.SetValue("Backup_WorkingFolder", value, transactionScope)
            transactionScope.SetClassFieldValue(GetType(Settings), "mWorkingFolder", value)
        End If
    End Sub

    Public Shared ReadOnly Property GlobalFileFilter() As Entities.Backup.FileFilter
        Get
            If Not mSettingsRead Then LoadSettings()
            Return mGlobalFileFilter
        End Get
    End Property
    Public Shared Sub SetGlobalFileFilter(ByVal filter As Entities.Backup.FileFilter, ByVal transactionScope As Framework.Data.TransactionScope)
        If Not mSettingsRead Then LoadSettings()
        Dim strSetting As String = Framework.Serialization.ToXml(filter)
        Framework.Data.MetaData.SetValue("Backup_GlobalFileFilter", strSetting, transactionScope)
        mGlobalFileFilter = filter
    End Sub


    Private Shared Sub LoadSettings()
        Dim strValue As String = Framework.Data.MetaData.GetValueAsString("Backup_GlobalFileFilter", Nothing)
        If strValue IsNot Nothing Then
            mGlobalFileFilter = Framework.Serialization.FromXml(Of Entities.Backup.FileFilter)(strValue)
        Else
            mGlobalFileFilter = New Entities.Backup.FileFilter
            mGlobalFileFilter.IncludeHiddenFiles = False
            mGlobalFileFilter.IncludeSystemFiles = False
            mGlobalFileFilter.ClearFileArchiveFlag = False
            mGlobalFileFilter.IncludePatterns = New Generic.List(Of Entities.MatchPattern)
            mGlobalFileFilter.IncludePatterns.Add(New Entities.MatchPattern(Entities.MatchPatternType.WildCard, "*.*"))
        End If
        mWorkingFolder = Framework.Data.MetaData.GetValueAsString("Backup_WorkingFolder", Nothing)
        mSettingsRead = True
    End Sub

End Class
